//--------------------------------------------------------------------------------------
// File: Tutorial02.fx
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------

cbuffer PerFrameConstants : register(b0)
{
	matrix WorldView;
	matrix Projection;
	float4 LightDir;
	float4 LightColour;
}

//Texture2D diffuse : register(t0);
//Texture2D lightmap : register(t1);
Texture2D texture0 : register(t0);
Texture2D texture1 : register(t1);
Texture2D texture2 : register(t2);
Texture2D texture3 : register(t3);
Texture2D texture4 : register(t4);
SamplerState samplerState : register(s0);

struct VS_INPUT
{
	float2 Tex : TEXCOORD0;
	float2 LightmapTex : TEXCOORD1;
	float4 Pos : POSITION;
};

struct PS_INPUT
{
	float4 Pos : SV_POSITION;
	float2 Tex : TEXCOORD0;
	float2 LightmapTex : TEXCOORD1;
};

//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{
	PS_INPUT output = (PS_INPUT)0;
	output.Pos = mul(input.Pos, WorldView);
	output.Pos = mul(output.Pos, Projection);
	output.Tex = input.Tex;
	output.LightmapTex = input.LightmapTex;

	return output;
}

//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS_DiffuseLightmap(PS_INPUT input) : SV_Target
{
//	float4 colour = diffuse.Sample(samplerState, input.Tex);
//	float4 light = lightmap.Sample(lightmapState, input.LightmapTex);
//	float4 blend = colour * light;
//	return saturate(blend);
	return float4(1.f, 1.f, 1.f, 1.f);
}

float4 PS_Diffuse(PS_INPUT input) : SV_Target
{
//	float4 colour = diffuse.Sample(samplerState, input.Tex);
//	return saturate(colour);
	return float4(1.f, 1.f, 1.f, 1.f);
}

float4 shader_1(PS_INPUT input) : SV_Target
{
	float4 stage0 = texture0.Sample(samplerState, input.Tex);
	return saturate(stage0);
}

float4 shader_2(PS_INPUT input) : SV_Target
{
	float4 stage0 = texture0.Sample(samplerState, input.LightmapTex);
	float4 stage1 = texture1.Sample(samplerState, input.Tex);
	return saturate(stage1 * stage0);
}

float4 shader_3(PS_INPUT input) : SV_Target
{
	float4 stage0 = texture0.Sample(samplerState, input.LightmapTex);
	float4 stage1 = texture1.Sample(samplerState, input.Tex);
	float4 stage2 = texture2.Sample(samplerState, input.Tex);
	return saturate(stage0 * stage1 * stage2);
}

float4 shader_4(PS_INPUT input) : SV_Target
{
	float4 stage0 = texture0.Sample(samplerState, input.LightmapTex);
	float4 stage1 = texture1.Sample(samplerState, input.Tex);
	float4 stage2 = texture2.Sample(samplerState, input.Tex);
	float4 stage3 = texture3.Sample(samplerState, input.Tex);
	return saturate(stage0 * stage1 * stage2 * stage3);
}


// Something like this?
//float4 PS_Q3Shader_2(PS_INPUT input) : SV_Target
//{
//	float4 src = textures[input.texutreId0].Sample(samplerState, input.texCoord0);
//	float4 dst = texrures[input.textureId1].Sample(samplerState, input.texCoord1);
//	float4 blend = (source * input.srcBlend0) + (dst * input.dstBlend0);
//	return blend;
//}
